//rpc.h
#ifndef RPC_H
#define RPC_H
#define MAXREQSTRING 10
#define RPC_SERVER_MAILBOX 1
#define RPC_CLIENT_MAILBOX 0
#define RPC_SERVER_ADDR 0
#define IS_SERVER 0

#define Max_RPC_LOCKNUM 50
#define Max_RPC_CVNUM 50


#define MAX_NAME 20
#define LOGIN_IN 1
#define LOGIN_SUCESS 1
#define MAX_USERNUM 5

#define RPC_LOCKAVAIABLE 0
#define RPC_LOCKINUSE 1


extern "C" {
    int bcopy(char *, char *, int);
};
//for the client to connected to the server
typedef struct ServerInfo
{
    unsigned int serverHaddr;
    unsigned int serverMail;
    unsigned int password;
};

typedef struct ClientInfo
{
    unsigned int clientHaddr;
    unsigned int clientmail;
    unsgined int isValid;
};

typedef struct RpcReqMessage
{
    int reqType;//the request type of the message
    int reqVersion;//optional to define the version of the request
    int reqIntParam1;//requestParm1 to store the param that need to send to the server
    int reqIntParam2;//requestParm2 to store the second param that need to send to the server(maybe used for the signal or wait)
    int requestFromAddr;//to show where the request from
    int requestFromMail;//to show where the request from
    int pingId; //ping MailBox id
    char reqStringParam[MAXREQSTRING];//to store the string param, used to store the name when created
    char reqStringParam1[MAXREQSTRING];

};
typedef struct RpcRplyMessage
{
    int ansType;//the request type of the message
    int ansVersion;//optional to define the version of the request
    int ansIntParam1;//requestParm1 to store the param that need to send to the server
    bool isValid;//to show this is a valid answer or not
    int replyToAddr;//to show where we should send this reply to
    int replyToMail;//to show where we should send this reply to
    int pingId; //ping MailBox id
};

typedef struct RPCLock
{
    char name[MAX_NAME];
    int ownerHdr;
    int ownerMdr;
    int state;
    List * waitList;//reply message waitqueue
};

typedef struct RPCCV
{
    char name[MAX_NAME];
    int waitinglockid;
    List * waitList;//reply message waitqueue
};

bool  sendRequest(RpcReqMessage * rrmsg);
void getReply(RpcRplyMessage * reply);

#endif
